package com.song.tools.songtest.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.song.tools.core.util.ObjectUtils;
import com.song.tools.mvc.manager.BaseManager;
import com.song.tools.songtest.beans.bo.SysUserBo;
import com.song.tools.songtest.beans.query.SysUserQuery;
import com.song.tools.songtest.convertor.SysUserConvertor;
import com.song.tools.songtest.dao.entity.SysUser;
import com.song.tools.songtest.dao.mapper.SysUserMapper;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 用户表 管理类
 * </p>
 *
 * @author song tools
 * @since 2024-07-09
 */
@Component
public class SysUserManager extends BaseManager<SysUser, SysUserBo, SysUserMapper, SysUserQuery, Long, SysUserConvertor> {

    @Override
    public LambdaQueryWrapper<SysUser> encapsulateQueryWrapper(SysUserQuery query) {
        LambdaQueryWrapper<SysUser> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getLoginAccount()), SysUser::getLoginAccount, query.getLoginAccount());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getUsername()), SysUser::getUsername, query.getUsername());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getProfilePhoto()), SysUser::getProfilePhoto, query.getProfilePhoto());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getSex()), SysUser::getSex, query.getSex());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getAge()), SysUser::getAge, query.getAge());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getBirthdayStart()), SysUser::getBirthday, query.getBirthdayStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getBirthdayEnd()), SysUser::getBirthday, query.getBirthdayEnd());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getPhone()), SysUser::getPhone, query.getPhone());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getEmail()), SysUser::getEmail, query.getEmail());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getStatus()), SysUser::getStatus, query.getStatus());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRemark()), SysUser::getRemark, query.getRemark());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getCreateTimeStart()), SysUser::getCreateTime, query.getCreateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getCreateTimeEnd()), SysUser::getCreateTime, query.getCreateTimeEnd());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getUpdateTimeStart()), SysUser::getUpdateTime, query.getUpdateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getUpdateTimeEnd()), SysUser::getUpdateTime, query.getUpdateTimeEnd());

        return queryWrapper;
    }

}
